import cv2
import matplotlib.pyplot as plt
import numpy as np
from holoviews.core.traversal import hierarchical
from matplotlib.mlab import magnitude_spectrum
from numba import uint8
from sympy.abc import epsilon

def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

img = cv2.imread('C:/Users/nic/Desktop/opencv/picture/girl.jpg',cv2.IMREAD_GRAYSCALE)

img_float32 = np.float32(img)

dft = cv2.dft(img_float32,flags=cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
#得到灰度图能够表示的形式
magnitude_spectrum = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))
cv_show('fourier',magnitude_spectrum)



